{extend name="layout/main" /}

{block name="header"}

{/block}

{block name="content"}
<link rel="stylesheet" href="https://cdn.staticfile.org/webuploader/0.1.5/webuploader.css">
<link rel="stylesheet" href="__PUBLIC__/admin/css/goods.css">
<script type="text/javascript" src='https://cdn.staticfile.org/webuploader/0.1.5/webuploader.min.js'></script>
<script src="__PUBLIC__/admin/js/wangEditor.min.js"></script>
<section class="panel">
    {if isset($info)}
    <header class="panel-heading">
        <h4>编辑商品</h4>
    </header>
    <div class="panel-body" style="padding-bottom: 50px">
        <form class="form-horizontal" method="post" onsubmit="return false" role="form">
            <input type="hidden" name="ispps" value="{$data.is_pp}">
            <input type="hidden" name="ppsks" value="{$data.ppsks}">
            <input type="hidden" class="pppptable" value="{$data.pptable}">
            <input type="hidden" class="pppptabdata" value="{$data.pptabdata}">
            <input name="id" type="hidden" value="{$data.id}">
            <div class="form-group">
                <label class="col-sm-2 control-label">标题</label>

                <div class="col-sm-5">
                    <input type="text" value="{$info.goods_title}" name="title" class="form-control"
                           placeholder="请输入标题">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">展示图片</label>
                <div class="col-sm-5">
                    <div id="fileList" class="uploader-list" style="float:right">
                        {if !empty($info.goods_pic)}
                        {foreach ($info.goods_pic as $key => $value) }
                        <div class="file-item thumbnail draggable-element " style="position:relative;">
                            <img src="__PUBLIC__{$value}">
                            <a class="file-panel" href="javascript:;" onclick="remove(this)">
                                <span class="fa fa-close"></span>
                            </a>
                            <input type="hidden" id="data_photo" name="photo[]" value="{$value}">
                        </div>
                        {/foreach}
                        {/if}
                    </div>
                    <div id="imgPicker" style="float:left">添加图片</div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">商品描述</label>

                <div class="col-sm-5">
                    <input type="text" value="{$info.goods_describe}" name="goods_describe" class="form-control"
                           placeholder="请输入商品描述">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">类型</label>

                <div class="col-sm-5">
                    <select name="category" class="form-control">
                        {foreach $cate as $item}
                        <option {if $info.category_id == $item->category_id}selected{/if} value="{$item->category_id}">{$item->category_title}</option>
                        {/foreach}
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">价格</label>

                <div class="col-sm-5">
                    <input type="text" value="{$info.goods_prices}" name="prices" class="form-control"
                           placeholder="请输入商品价格">
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-2 control-label">库存</label>

                <div class="col-sm-5">
                    <input type="text" value="{$info.goods_num}" name="num" class="form-control"
                           placeholder="请输入商品库存">
                </div>
            </div>

            <div class="form-group ppio">
                <label class="col-sm-2 control-label">商品型号</label>
                <div class="col-sm-5"><span class="btn btn-default btnAddPP">添加商品型号</span></div>
            </div>
            <div class="form-group tabpp">
                <label class="col-sm-2 control-label">商品型号</label>
                <div class="col-sm-5" style="width: 80%">
                    <ul class="pplist"></ul>
                    <div class="ppfoot">
                        <span class="btn btn-default btnPP">添加型号分类</span>
                    </div>
                </div>
            </div>
            <div class="form-group tabpps">
                <label class="col-sm-2 control-label">价格与库存</label>
                <div class="col-sm-5" style="width: 80%">
                    <table border="1">
                        <thead>
                        <tr>
                            <td>型号</td>
                            <!--<td>金钻</td>-->
                            <!--<td>银钻</td>-->
                            <td>库存</td>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                        <tfoot>
                        <tr>
                            <td><b>批量修改</b></td>
                            <!--<td><input type="text"></td>-->
                            <!--<td><input type="text"></td>-->
                            <td><input type="text"></td>
                        </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
          
            <div class="form-group">
                <label class="col-sm-2 control-label">内容</label>

                <div class="col-sm-10"  style="width: 480px;min-height: 600px" id="editor">
                    {:htmlspecialchars_decode($info.goods_content)}
                </div>
            </div>
            <textarea style="display: none;" id="content" name="content"></textarea>

            <div class="form-group">
                <label class="col-sm-2 control-label">排序</label>

                <div class="col-sm-5">
                    <input type="text" value="{$info.sort ? $info.sort : 100}" name="sort" class="form-control"
                           placeholder="排序">
                </div>
                <div class="col-sm-5 help-block">
                    数字越小，排到最前面
                </div>
            </div>
            <div class="form-group" style="display: none">
                <label class="col-sm-2 control-label">首页是否显示</label>

                <div class="col-sm-8">
                    <label class="radio radio-custom pull-left">
                        <input type="radio" {if $info.is_index == 1}checked{/if} name="is_index" value="1">
                        <i class="radio "></i> 显示
                    </label>
                    <label class="radio radio-custom pull-left">
                        <input type="radio" {if $info.is_index == 2}checked{/if} name="is_index" value="2">
                        <i class="radio "></i> 不显示
                    </label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">是否发布</label>

                <div class="col-sm-8">
                    <label class="radio radio-custom pull-left">
                        <input type="radio" {if $info.status == 1}checked{/if} name="status" value="1">
                        <i class="radio "></i> 发布
                    </label>
                    <label class="radio radio-custom pull-left">
                        <input type="radio" {if $info.status == 0}checked{/if} name="status" value="0">
                        <i class="radio "></i> 不发布
                    </label>
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit" data-url="{:url('admin/shop/update',['id'=>$info.id])}"
                            onclick="main.ajaxPosts(this)" class="btn btn-primary">确定修改
                    </button>
                </div>
            </div>
        </form>
    </div>
    {else /}
    <header class="panel-heading">
        <h4>添加商品</h4>
    </header>
    <div class="panel-body" style="padding-bottom: 50px">
        <form class="form-horizontal" method="post" onsubmit="return false" role="form">
            <input type="hidden" name="ispps" value="0">
            <input type="hidden" name="ppsks" value="">
            <input name="id" type="hidden" value="">
            <div class="form-group">
                <label class="col-sm-2 control-label">标题</label>

                <div class="col-sm-5">
                    <input type="text" value="" name="title" class="form-control"
                           placeholder="请输入商品标题">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">展示图片</label>
                <div class="col-sm-5">
                    <div id="fileList" class="uploader-list" style="float:right">

                    </div>
                    <div id="imgPicker" style="float:left">添加图片</div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">商品描述</label>

                <div class="col-sm-5">
                    <input type="text" value="" name="goods_describe" class="form-control"
                           placeholder="请输入商品描述">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">类型</label>

                <div class="col-sm-5">
                    <select name="category" class="form-control">
                        {foreach $cate as $item}
                        <option value="{$item->category_id}">{$item->category_title}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">价格</label>

                <div class="col-sm-5">
                    <input type="text" value="" name="prices" class="form-control"
                           placeholder="请输入商品价格">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">库存</label>

                <div class="col-sm-5">
                    <input type="text" value="" name="num" class="form-control"
                           placeholder="请输入商品库存">
                </div>
            </div>



            <div class="form-group ppio">
                <label class="col-sm-2 control-label">商品型号</label>
                <div class="col-sm-5"><span class="btn btn-default btnAddPP">添加商品型号</span></div>
            </div>
            <div class="form-group tabpp">
                <label class="col-sm-2 control-label">商品型号</label>
                <div class="col-sm-5" style="width: 80%">
                    <ul class="pplist"></ul>
                    <div class="ppfoot">
                        <span class="btn btn-default btnPP">添加型号分类</span>
                    </div>
                </div>
            </div>
            <div class="form-group tabpps">
                <label class="col-sm-2 control-label">价格与库存</label>
                <div class="col-sm-5" style="width: 80%">
                    <table border="1">
                        <thead>
                        <tr>
                            <td>型号</td>
                            <!--<td>金钻</td>-->
                            <!--<td>银钻</td>-->
                            <td>库存</td>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                        <tfoot>
                        <tr>
                            <td><b>批量修改</b></td>
                            <!--<td><input type="text"></td>-->
                            <!--<td><input type="text"></td>-->
                            <td><input type="text"></td>
                        </tr>
                        </tfoot>
                    </table>
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-2 control-label">内容描述</label>

                <div class="col-sm-10" style="width: 480px;min-height: 600px" id="editor">

                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">排序</label>

                <div class="col-sm-5">
                    <input type="text" value="100" name="sort" class="form-control"
                           placeholder="排序">
                </div>
                <div class="col-sm-5 help-block">
                    数字越小，排到最前面
                </div>
            </div>
            <textarea style="display: none;" id="content" name="content"></textarea>

            <div class="form-group" style="display: none">
                <label class="col-sm-2 control-label">首页是否显示</label>

                <div class="col-sm-8">
                    <label class="radio radio-custom pull-left">
                        <input type="radio" checked name="is_index" value="1">
                        <i class="radio "></i> 显示
                    </label>
                    <label class="radio radio-custom pull-left">
                        <input type="radio"  name="is_index" value="2">
                        <i class="radio "></i> 不显示
                    </label>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">是否发布</label>

                <div class="col-sm-5">
                    <label class="radio radio-custom pull-left">
                        <input type="radio" checked name="status" value="1">
                        <i class="radio "></i> 发布
                    </label>
                    <label class="radio radio-custom pull-left">
                        <input type="radio" name="status" value="0">
                        <i class="radio "></i> 不发布
                    </label>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button type="submit"onclick="$(this).hide();main.ajaxPosts(this);" data-url="{:url('admin/shop/save')}"
                            class="btn btn-primary">提交
                    </button>
                </div>
            </div>
        </form>
    </div>
    {/if}
</section>
{/block}


{block name="footer"}
<script src="__PUBLIC__/admin/vendor/fuelux/radio.js"></script>
<script>
    var E = window.wangEditor;
    var editor = new E('#editor');
    var $content = $('#content');
    editor.customConfig.uploadFileName = 'image'
    editor.customConfig.uploadImgServer = "{:url('upload/uploadEditor')}";
    editor.customConfig.onchange = function (html) {
        // 监控变化，同步更新到 textarea
        $content.val(html)
    };
    editor.customConfig.menus = [
        'head',  // 标题
        'bold',  // 粗体
        'fontSize',  // 字号
        'fontName',  // 字体
        'foreColor',  // 文字颜色
        'backColor',  // 背景颜色
        'link',  // 插入链接
        'list',  // 列表
        'justify',  // 对齐方式
        'quote',  // 引用
        'image',  // 插入图片
    ]
    editor.create()

    $(function(){
        $(".w-e-text-container").css('height','600px')
    })

</script>
<script >
    var $list = $('#fileList');
    var uploader = WebUploader.create({
        auto: true,// 选完文件后，是否自动上传。
        swf: '/static/admin/js/webupload/Uploader.swf',// swf文件路径 换成你的接收路径
        server: "{:url('upload/uploadImg')}",// 文件接收服务端 换成你的接收路径
        duplicate :true,// 重复上传图片，true为可重复false为不可重复
        pick: '#imgPicker',// 选择文件的按钮
        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/jpg,image/jpeg,image/png'
        },

        'onUploadSuccess': function(file, data, response) {
            var up_src = data._raw.replace("\\", "\/");
            var ph_src = JSON.parse(up_src);
            console.log(ph_src);
            ph_src = ph_src.data[0].replace("\/\/", "\/");
            ph_src = ph_src.replace("\\", "\/");

            //上传成功后显示图片
            var $li = $(
                '<div id="' + file.id + '" class="file-item thumbnail draggable-element d-"'+file.id.substr(file.id.length-1,1)+' style="position:relative;">' +
                '<img>' +
                '<a class="file-panel" href="javascript:;" onclick="remove(this)">' +
                '<span class="fa fa-close"></span>' +
                '</a>' +
                '<input type="hidden" id="data_photo" name="photo[]" value="'+ph_src+'">' +
                '</div>'
                ),
                $img = $li.find('img');

            // $list为容器jQuery实例
            $list.append( $li );

            // 创建缩略图 如果为非图片文件，可以不用调用此方法 100（宽） x 100（高）
            uploader.makeThumb( file, function( error, src ) {
                if ( error ) {
                    $img.replaceWith('<span>不能预览</span>');
                    return;
                }
                $img.attr( 'src', src );
            }, 100, 100 );
        }
    });


    // 当有文件添加进来的时候
    uploader.on( 'fileQueued', function( file ) {

    });

    // 文件上传成功
    uploader.on( 'uploadSuccess', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传成功！');
    });

    // 文件上传失败，显示上传出错。
    uploader.on( 'uploadError', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传出错!');
    });

    /**
     * [remove 移除图片]
     * @post  [file]  [文件名 （必填）]
     * @post  [obj]  [操作对象] [前台操作数据 移除dom标志]
     *
     * @return
     * @Author[summer 1012684399@qq.com] THINK MORE DO LESS
     */
    function remove(obj){
        // console.log(12);

        $(obj).parent('div').remove();
        var html = '<input type="hidden" id="data_photo" name="remove[]" value="">';
        $('#fileList').append(html);
    }
</script>
<script src="__PUBLIC__/admin/js/goods.js"></script>
<script>
    var pptable = $('.pppptable').val();
    var pptabdata = $('.pppptabdata').val();
    console.log(pptabdata);
    {notempty name="data.is_pp"}$('.btnAddPP').click();{/notempty}
        {notempty name="data.pptable"}getPPs(<?php echo $data['pptable'] ?>,<?php echo $data['pptabdata'] ?>);{/notempty}

</script>
{/block}